<?php

/**
 * BuddyPress - Groups Loop
 *
 * Querystring is set via AJAX in _inc/ajax.php - bp_dtheme_object_filter()
 *
 * The code in this file is adapted from group-loop.php. This code is customized
 * to only display 4 groups per page.
 */

?>

<?php do_action( 'bp_before_groups_loop' ); 

/* Set the following parameters in bp_has_groups:
 * 1. per_page = 4; displays 4 groups per page
 * 2. user_id = bp_loggedin_user_id(); displays only groups that this user is a member of.
 */   ?>
<?php if ( bp_has_groups( bp_ajax_querystring( 'groups' ).'&per_page=4&user_id='.bp_loggedin_user_id() ) ) : ?>

	<div id="groups-home-pag-top" class="pagination">

		<div class="pag-count" id="group-dir-count-top">

			<?php bp_groups_pagination_count(); ?>

		</div>

		<div class="pagination-links" id="group-dir-pag-top">

			<?php bp_groups_pagination_links(); ?>

		</div>

	</div>
	
	<?php do_action( 'bp_before_directory_groups_list' ); ?>

	<ul id="groups-home-groups-list" class="item-list" role="main">
		
	<?php while( bp_groups() ) :

		bp_the_group();  ?>

			<li>

				<div id="groups-loop-title" class="item">
					
					<div class="item-title"><a href="<?php bp_group_permalink(); ?>"><?php bp_group_name(); ?></a></div>
					<div class="item-meta"><span class="activity"><?php printf( __( 'active %s', 'buddypress' ), bp_get_group_last_active() ); ?></span></div>
				
					<?php do_action( 'bp_directory_groups_item' ); ?>

				</div>
				
				<?php if( bp_get_group_type() != 'Public Group' ) { ?>
					<div class="item-avatar">
						<a href="<?php bp_group_permalink(); ?>"><?php bp_group_avatar( 'type=thumb&width=50&height=50' ); ?></a>
					</div>
				<?php } ?>
							
				<div class="action">

					<?php //do_action( 'bp_directory_groups_actions' ); ?>

					<div class="meta">

						<?php bp_group_type(); ?> / <?php bp_group_member_count(); ?>

					</div>

				</div>

				<div class="clear"></div>
			</li>
			
	<?php endwhile;  ?>

	</ul>

	<?php do_action( 'bp_after_directory_groups_list' ); ?>


<?php else: ?>

	<div id="message" class="info">
		<p><?php _e( 'There were no groups found.', 'buddypress' ); ?></p>
	</div>

<?php endif; ?>

<?php do_action( 'bp_after_groups_loop' ); ?>
